<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="module">
        let txt = `甲子乙丑海中金 丙寅丁卯炉中火 戊辰己巳大林木
庚午辛未路旁土 壬申癸酉剑锋金 甲戌乙亥山头火
丙子丁丑涧下水 戊寅己卯城墙土 庚辰辛巳白蜡金
壬午癸未杨柳木 甲申乙酉泉中水 丙戌丁亥屋上土
戊子己丑霹雳火 庚寅辛卯松柏木 壬辰癸巳长流水
甲午乙未沙中金 丙申丁酉山下火 戊戌己亥平地木
庚子辛丑壁上土 壬寅癸卯金箔金 甲辰乙巳佛灯火
丙午丁未天河水 戊申己酉大驿土 庚戌辛亥钗钏金
壬子癸丑桑柘木 甲寅乙卯大溪水 丙辰丁巳沙中土
戊午己未天上火 庚申辛酉石榴木 壬戌癸亥大海水`;
      
        function getScope(input) {
            let length = input.length;
            let words = [];
            let dic = {};
            for (let i = 0; i < length; i++) {
                let word = input[i];
                if (words.includes(word)) {
                    dic[word].l += 1;
                } else {
                    words.push(word);
                    dic[word] = {
                        c:word.charCodeAt(0),
                        l:1
                    }
                }
            }
            return {
                length,
                words,
                dic
            }
        }
        let result=getScope(txt);
        console.warn(result);
        let data=   result.words.sort((a,b)=>{
            return result.dic[b].l-result.dic[a].l
        }).map(p=>{
            
         return    {p,...result.dic[p]}
        });
        console.warn("data",data);
    </script>
</body>

</html>